import React, { Component } from 'react'
import {Link} from 'react-router-dom'
import './homehead.less'
import {connect} from 'react-redux'
import Searchinput from '../../../components/searchinput/searchinput'
import {withRouter} from 'react-router'
 class HomeHead extends Component{
     componentDidMount(){
         console.log(this.props.city)
         this.props.newdata(this.props.city)
     }
     toshopcar=()=>{
         if(this.props.user){
             this.props.history.push('/shopcar')
         }else{
            this.props.history.push('/login')
         }
     }
    render(){
        return(
            <div className='homehead'>
                <div className='curcity'>
                    <Link to='/city'>{this.props.city}</Link>
                    <i className='iconfont icon-xialajiantou'></i>
                </div>
                <div className='searchbox'>
                    <i className='iconfont icon-sousuo'></i>
                    {/* <input type="text" placeholder='请输入搜索的内容'/> */}
                    <Searchinput/>
                </div>
                <div className='shopcar'>
                    <i 
                        className='iconfont icon-gouwucheman'
                        onClick={this.toshopcar}
                    ></i>
                </div>
            </div>
        )
    }
}
function mapStateToProps(state){
    return{
        city:state.city,
        user:state.user
    }
}
export default connect(mapStateToProps)(withRouter(HomeHead))